package com.siyu.gis.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.siyu.basedata.rsvrgis.domain.RsvrGis;
import com.siyu.basedata.rsvrgis.service.IRsvrGisService;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.utils.uuid.IdUtils;
import com.siyu.gis.service.GisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/gis")
public class GisController {

    @Autowired
    private IRsvrGisService rsvrGisService;
    @Autowired
    private GisService gisService;

    /**
     * 获取地图gis信息
     * @param rscd
     * @return
     */

    @GetMapping("/rsvr/detail")
    public AjaxResult getRsvrgis(String rscd) {
        try {
            RsvrGis rsvrGis = rsvrGisService.lambdaQuery().eq(RsvrGis::getRscd, rscd).one();
            return AjaxResult.success(rsvrGis);
        } catch (Exception e) {
            return AjaxResult.error("数据获取异常！");
        }
    }

    /**
     * 添加水库数据
     * @param rsvrUrl
     * @param upBasinUrl
     * @param downBasinUrl
     * @param upRiverUrl
     * @param downRiverUrl
     * @param rscd
     * @return
     */
    @PostMapping(value = "/rsvr/gisadd", consumes = "multipart/form-data")
    public ResponseEntity<AjaxResult> uploadgeo(@RequestParam(value = "rsvrUrl",required=false) MultipartFile rsvrUrl,
                                                @RequestParam(value = "upBasinUrl",required=false) MultipartFile upBasinUrl,
                                                @RequestParam(value = "downBasinUrl",required=false) MultipartFile downBasinUrl,
                                                @RequestParam(value = "upRiverUrl",required=false) MultipartFile upRiverUrl,
                                                @RequestParam(value = "downRiverUrl",required=false) MultipartFile downRiverUrl,
                                                @RequestParam("rscd")String rscd){
        return gisService.uploadgeo(rsvrUrl,upBasinUrl,downBasinUrl,upRiverUrl,downRiverUrl,rscd);
    }
}
